package com.nfu.zlsp.dev.controller;

import com.alibaba.fastjson.JSONObject;
import com.nfu.zlsp.dev.common.constants.TheConstant;
import com.nfu.zlsp.dev.common.utils.PageUtils;
import com.nfu.zlsp.dev.common.utils.R;
import com.nfu.zlsp.dev.entity.AddressEntity;
import com.nfu.zlsp.dev.entity.ConsignEntity;
import com.nfu.zlsp.dev.entity.UserEntity;
import com.nfu.zlsp.dev.service.AddressService;
import com.nfu.zlsp.dev.service.ConsignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 跳转页面
 */
@Controller
public class JumpPageController {

    @Autowired
    private AddressService addressService;



    /**
     * todo 页面权限范围过滤器
     */


    /**
     * 跳转到用户信息页面
     * @return
     */
    @RequestMapping("/toUserInfo")
    public String toUserInfo(){
        return "/userInfo";
    }

    @RequestMapping("/toUserInfoTransport")
    public String toUserInfoTransport(){
        return "/userInfo_transport";
    }


    /**
     * 退出登录
     */
    @RequestMapping("/logOut")
    public String logOut(HttpSession session){
        session.setAttribute(TheConstant.USER_INFO,null);
        return "/login";
    }

    /**
     * 退出登录
     */
    @RequestMapping("/logOutTransport")
    public String logOutTransport(HttpSession session){
        session.setAttribute(TheConstant.USER_INFO_TRANSPORT,null);
        return "/login";
    }

    /**
     * 跳转到登录页面
     * @return
     */
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "/login";
    }

    /**
     * 跳转到注册页面
     * @return
     */
    @RequestMapping("/toRegister")
    public String toRegister(){
        return "/register";
    }

    /**
     * 跳转到查询（托运方）页面
     * @return
     */
    @RequestMapping(value = "toListQueryConsign",method = RequestMethod.GET)
    public String toListQueryConsign(Map<String,Object> map){

        String addressId = "110000";
        String cityAddressId = "110100";
        System.out.println("获取省份信息");
        List<AddressEntity> addressList = addressService.getRoot();
        System.out.println("获取cityAddreessId的的区级地址信息：" + addressId);
        List<AddressEntity> cityAddress = addressService.getList(null, addressId);
        System.out.println("获取cityAddreessId的区级地址信息:" + cityAddressId);
        List<AddressEntity> districtAddress = addressService.getList(null, cityAddressId);
        map.put("addressList", addressList);
        map.put("cityList", cityAddress);
        map.put("districtList", districtAddress);
        map.put("addressId", addressId);
        map.put("cityAddressId", cityAddressId);
        System.out.println("跳转托运拼单页面");
        return "/listQuery_Consign";
    }


    /**
     * 跳转到查询（托运方）页面
     * @return
     */
    @RequestMapping(value = "toListQueryTransport",method = RequestMethod.GET)
    public String toListQueryTransport(Map<String,Object> map){

        String addressId = "110000";
        String cityAddressId = "110100";
        System.out.println("获取省份信息");
        List<AddressEntity> addressList = addressService.getRoot();
        System.out.println("获取cityAddreessId的的区级地址信息：" + addressId);
        List<AddressEntity> cityAddress = addressService.getList(null, addressId);
        System.out.println("获取cityAddreessId的区级地址信息:" + cityAddressId);
        List<AddressEntity> districtAddress = addressService.getList(null, cityAddressId);
        map.put("addressList", addressList);
        map.put("cityList", cityAddress);
        map.put("districtList", districtAddress);
        map.put("addressId", addressId);
        map.put("cityAddressId", cityAddressId);
        System.out.println("跳转托运拼单页面");
        return "/page_t/listQuery_Transport";
    }



    /**
     * 跳转托运拼单页面前进行地址信息获取
     * 跳转托运拼单发布页面
     */
    @RequestMapping(value = "getAddressInfo", method = RequestMethod.GET)
    public String getAddressInfo(Map<String,Object> map) {
        String addressId = "110000";
        String cityAddressId = "110100";
        System.out.println("获取省份信息");
        List<AddressEntity> addressList = addressService.getRoot();
        System.out.println("获取cityAddreessId的的区级地址信息：" + addressId);
        List<AddressEntity> cityAddress = addressService.getList(null, addressId);
        System.out.println("获取cityAddreessId的区级地址信息:" + cityAddressId);
        List<AddressEntity> districtAddress = addressService.getList(null, cityAddressId);
        map.put("addressList", addressList);
        map.put("cityList", cityAddress);
        map.put("districtList", districtAddress);
        map.put("addressId", addressId);
        map.put("cityAddressId", cityAddressId);
        System.out.println("跳转托运拼单页面");
        return "/listRelease_Consign";

    }

    /**
     * 跳转托运拼单页面前进行地址信息获取
     * 跳转承运拼单发布页面
     */
    @RequestMapping(value = "toTransport", method = RequestMethod.GET)
    public String toTransport(Map<String,Object> map) {
        String addressId = "110000";
        String cityAddressId = "110100";
        System.out.println("获取省份信息");
        List<AddressEntity> addressList = addressService.getRoot();
        System.out.println("获取cityAddreessId的的区级地址信息：" + addressId);
        List<AddressEntity> cityAddress = addressService.getList(null, addressId);
        System.out.println("获取cityAddreessId的区级地址信息:" + cityAddressId);
        List<AddressEntity> districtAddress = addressService.getList(null, cityAddressId);
        map.put("addressList", addressList);
        map.put("cityList", cityAddress);
        map.put("districtList", districtAddress);
        map.put("addressId", addressId);
        map.put("cityAddressId", cityAddressId);
        System.out.println("跳转托运拼单页面");
        return "/page_t/listRelease_Transport";

    }

    /**
     * 跳转 我的发布(承运方) 界面
     */

    @RequestMapping(value = "/toMyReleaseConsign")
    public String toMyReleaseConsign(Map<String,Object> map, HttpSession session){
        return "/myRelease_Consign";
    }

    /**
     * 跳转 我的发布(承运方) 界面
     */

    @RequestMapping(value = "/toMyReleaseTransport")
    public String toMyReleaseTransport(Map<String,Object> map, HttpSession session){
        return "/page_t/myRelease_Transport";
    }




    /**
     * 跳转 订单管理页面(承运方)
     */
    @RequestMapping("/toOrderManagementConsign")
    public String toManagementConsign(Map<String,Object> map){
        String addressId = "110000";
        String cityAddressId = "110100";
        System.out.println("获取省份信息");
        List<AddressEntity> addressList = addressService.getRoot();
        System.out.println("获取cityAddreessId的的区级地址信息：" + addressId);
        List<AddressEntity> cityAddress = addressService.getList(null, addressId);
        System.out.println("获取cityAddreessId的区级地址信息:" + cityAddressId);
        List<AddressEntity> districtAddress = addressService.getList(null, cityAddressId);
        map.put("addressList", addressList);
        map.put("cityList", cityAddress);
        map.put("districtList", districtAddress);
        map.put("addressId", addressId);
        map.put("cityAddressId", cityAddressId);
        System.out.println("跳转托运拼单页面");
        return "/orderManagement_Consign";
    }

    /**
     * 跳转 订单管理页面(托运方)
     */
    @RequestMapping("/toOrderManagementTransport")
    public String toTransportConsign(Map<String,Object> map){
        String addressId = "110000";
        String cityAddressId = "110100";
        System.out.println("获取省份信息");
        List<AddressEntity> addressList = addressService.getRoot();
        System.out.println("获取cityAddreessId的的区级地址信息：" + addressId);
        List<AddressEntity> cityAddress = addressService.getList(null, addressId);
        System.out.println("获取cityAddreessId的区级地址信息:" + cityAddressId);
        List<AddressEntity> districtAddress = addressService.getList(null, cityAddressId);
        map.put("addressList", addressList);
        map.put("cityList", cityAddress);
        map.put("districtList", districtAddress);
        map.put("addressId", addressId);
        map.put("cityAddressId", cityAddressId);
        System.out.println("跳转托运拼单页面");
        return "/page_t/orderManagement_Transport";
    }


    /**
     * 跳转管理后台，页面还没写喔！！！！！
     */
    @RequestMapping("toAdminIndex")
    public String toAdminIndex(){
        return "/admin/index";
    }


    /**
     * 跳转 我拼的单(承运方) 界面
     */

    @RequestMapping("/toOrderManagementConsignElse")
    public String toManagementConsignElse(Map<String,Object> map){
        String addressId = "110000";
        String cityAddressId = "110100";
        System.out.println("获取省份信息");
        List<AddressEntity> addressList = addressService.getRoot();
        System.out.println("获取cityAddreessId的的区级地址信息：" + addressId);
        List<AddressEntity> cityAddress = addressService.getList(null, addressId);
        System.out.println("获取cityAddreessId的区级地址信息:" + cityAddressId);
        List<AddressEntity> districtAddress = addressService.getList(null, cityAddressId);
        map.put("addressList", addressList);
        map.put("cityList", cityAddress);
        map.put("districtList", districtAddress);
        map.put("addressId", addressId);
        map.put("cityAddressId", cityAddressId);
        System.out.println("跳转托运拼单页面");
        return "/orderManagement_Consign_else";
    }

    /**
     * 跳转 我拼的单(承运方) 界面
     */

    @RequestMapping("/toManagementTransportElse")
    public String toManagementTransportElse(Map<String,Object> map){
        String addressId = "110000";
        String cityAddressId = "110100";
        System.out.println("获取省份信息");
        List<AddressEntity> addressList = addressService.getRoot();
        System.out.println("获取cityAddreessId的的区级地址信息：" + addressId);
        List<AddressEntity> cityAddress = addressService.getList(null, addressId);
        System.out.println("获取cityAddreessId的区级地址信息:" + cityAddressId);
        List<AddressEntity> districtAddress = addressService.getList(null, cityAddressId);
        map.put("addressList", addressList);
        map.put("cityList", cityAddress);
        map.put("districtList", districtAddress);
        map.put("addressId", addressId);
        map.put("cityAddressId", cityAddressId);
        System.out.println("跳转托运拼单页面");
        return "/page_t/orderManagement_Transport_else";
    }


    /**
     * test
     */

    @RequestMapping("testTransport")
    public String testTransport(){
        return "/page-temp/listQuery_Transport";
    }

    @RequestMapping("testConsign")
    public String testConsign(){
        return "/page-temp/listQuery_Consign";
    }


}












